<?php

namespace App\Http\Controllers\Api;

use App\Helpers\Libraries\ImageLibrary;
use App\Http\Controllers\BaseController;
use App\Http\Requests\User\RegisterRequest;
use App\Http\Resources\Api\UserResource;
use App\Jobs\TestJob;
use App\Models\User\User;
use Carbon\Carbon;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\Response;

class TestController extends BaseController
{

    /**
     * 测试任务队列
     */
    public function testJob()
    {
        // 队列任务
//        $userId = 1;
//        TestJob::dispatch($userId);
    }

    /**
     * 资源数据列
     */
    public function collection()
    {
        // 单行用户自定义资源信息返回
//        $user = User::first();
//        return $this->success(new UserResource($user));
        // 多行用户自定义资源信息返回
        $users = User::get();
        return $this->success(UserResource::collection($users));
    }

    /**
     * 生成二维码
     * @return Response|mixed
     * @throws BindingResolutionException
     */
    public function createQRCode()
    {
        return ImageLibrary::createQRCode(1, 'www.xxx.com');
    }

    /**
     * 合成海报
     * @return Response|mixed
     * @throws BindingResolutionException
     */
    public function createShareImage()
    {
        $text1 = '活动时间：2021年5月20日-2022年5月20日';
        $text2 = '活动一：扫码加群抢5至99元大面额红包';
        $text3 = '活动二：购买产品即可获得专属刻字保温杯'."\n".'一个';
        return ImageLibrary::createShareImage('www.xxx.com', 'images/share_image.png', $text1, $text2, $text3);
    }

    public function testApi(RegisterRequest $registerRequest)
    {
        $registerInput = $registerRequest->toArray();
        /** @var User $user */
        dd($registerInput['mobile']);
    }
}
